RemoveDuplicates Generic Method

Wintellect PowerCollections

Collapse imageExpand ImageCollapseAll imageExpandAll imageDropDown imageDropDownHover imageCopy imageCopyHover image
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Remove consecutive "equal" items from a collection, yielding another collection. In each run of consecutive equal items in the collection, all items after the first item in the run are removed. The passed BinaryPredicate is used to determine if two items are "equal".

Namespace: Wintellect.PowerCollections
Assembly:  PowerCollections (in PowerCollections.dll)

Syntax

C#
public static IEnumerable<T> RemoveDuplicates<T>(
	IEnumerable<T> collection,
	BinaryPredicate<T> predicate
)
Visual Basic (Declaration)
Public Shared Function RemoveDuplicates(Of T) ( _
	collection As IEnumerable(Of T), _
	predicate As BinaryPredicate(Of T) _
) As IEnumerable(Of T)
Visual C++
public:
generic<typename T>
static IEnumerable<T>^ RemoveDuplicates (
	IEnumerable<T>^ collection, 
	BinaryPredicate<T>^ predicate
)

Parameters

collection
IEnumerable<(Of <T>)>
The collection to process.
predicate
BinaryPredicate<(Of <T>)>
The BinaryPredicate used to compare items for "equality". An item current is removed if predicate(first, current)==true, where first is the first item in the group of "duplicate" items.

Return Value

An new collection with the items from collection, in the same order, with consecutive "duplicates" removed.

Type Parameters

T

Remarks

Since an arbitrary BinaryPredicate is passed to this function, what is being removed need not be true equality.

See Also